/**
 * 车辆详情对话框（可用于添加和修改对话框）
 */
var CarInfoDlg = {
    data: {
        carId: "",
        carType: "",
        carColor: "",
        carPrice: "",
        carInspection: "",
        carMileage: "",
        rentMoneyOneDay: "",
        modifyId: "",
        ticketId: "",
        rentTimes: "",
        carScore: ""
    }
};

var toVal = {
    getVal: function (name) {
        return $("#"+ name).val();
    }
}

CarInfoDlg.validateForm = function () {

    var data = CarInfoDlg.data;

    if (!data.carType) {
        return "请输入类型";
    }
    if (!data.carColor) {
        return "请输入颜色";
    }
    if (!data.carPrice) {
        return "请输入保值";
    }
    if (!data.rentMoneyOneDay) {
        return "请输入租赁价格";
    }
    return true;
};


/**
 * 关闭此对话框
 */
CarInfoDlg.close = function () {
    parent.layer.close(window.parent.car.layerIndex);
};

/**
 * 提交添加车辆
 */
CarInfoDlg.addSubmit = function () {
    //注意！vue的model绑定和layui有冲突！手动赋值一下！
    //UserInfoDlg.data.birthday = Feng.getLaydate();

    var ajax = new $ax(Feng.ctxPath + "/car/add", function (data) {
        window.parent.Feng.success("添加成功!");
        window.parent.car.table.refresh();
        CarInfoDlg.close();
    }, function (data) {
        window.parent.Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    this.data.modifyId = toVal.getVal("moId");
    this.data.ticketId = toVal.getVal("tiId");
    ajax.set(this.data);
    ajax.start();
};

$(function () {

    CarInfoDlg.app = new Vue({
        el: '#carForm',
        data: CarInfoDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            //表单验证
            ensure: function () {
                var result = CarInfoDlg.validateForm();
                if (result === true) {
                    CarInfoDlg.addSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                CarInfoDlg.close();
            }
        }
    });
});
